Skip to content

fix: cast typed writes to int for integer OPC UA channels - #8

Merged
simontaurus merged 4 commits into
mainfrom
fix/typed-write-integer-cast
Aug 6, 2026
Merged

fix: cast typed writes to int for integer OPC UA channels#8
simontaurus merged 4 commits into
mainfrom
fix/typed-write-integer-cast

Conversation

@simontaurus

Copy link
Copy Markdown
Contributor

What

Three commits:

  1. write_channel_typed casts the converted magnitude to int when the
    channel's data_type is an integer type. A unit conversion always
    yields a float, so writing to an Int16/Int32/UInt32 node raised
    TypeError: an integer is required.
  2. The integer set is classified via asyncua.ua.VariantType (2..9)
    rather than a hand-written list of names, since the channel schema's
    data_type enum matches that numbering.
  3. Drops the local get_channel_by_osw_id in favour of the shared one
    now in DataToolMixin.

Depends on OpenSemanticWorld-Packages/opensemantic.base-python#8 for
commit 3.

Why

Process parameters are stored in their own units (minutes, seconds,
Celsius) and converted on write. Every integer-typed parameter channel
was unwritable through the typed path.

Test

Adds tests/test_controller.py coverage for the integer cast, including
a rounding case and a float channel that must stay a float. Full suite
green locally. Exercised in vac-station-opcua-client against 35
parameter channels, byte-identical to the previous manual conversion.

- write_channel_typed converts to the channel's unit, which yields a float
- asyncua does not coerce it: encoding a float into an Int32 variant raises
  "required argument is not an integer"
- cast when the channel declares an integer type; float channels untouched
OpcUaDataType mirrors ua.VariantType, whose numbering is fixed by the OPC UA
specification, so SByte (2) through UInt64 (9) identifies the integer types
without a hard-coded name list.
get_channel_by_osw_id moved to DataToolMixin, where the surrounding
channel traversal helpers already live.
@simontaurus
simontaurus merged commit 32108ab into main Aug 6, 2026
12 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant